package com.tool.weixin.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.slf4j.Logger;

public class ToolProperties extends Properties {
	
	private static final long serialVersionUID = 8677007364538968282L;

	private static final Logger logger = org.slf4j.LoggerFactory.getLogger(ToolProperties.class);

	
	public ToolProperties(String name) {
		FileInputStream fis = null;
		String realPath = null;
		try {
			realPath = ToolProperties.class.getClassLoader().getResource("").toURI().getPath();
			// 把文件读入文件输入流，存入内存中  
			fis = new FileInputStream(new File(realPath + name));  
			//加载文件流的属性     
			this.load(fis);
		} catch (Exception e) {
			logger.info("微信读取配置文件错误:" + realPath + name);
		} finally {
			if(fis != null) {
				try {
					fis.close();
				} catch (IOException e) {
				}
			}
		}
	}

	public String getString(String key) {
		logger.debug(key);
		if(this.getProperty(key) != null) {
			return this.getProperty(key);
		}
		return "";
	}
	
	public String getString(String key,String defaultValue) {
		logger.debug(key);
		if(this.getProperty(key) != null) {
			return this.getProperty(key);
		}
		return defaultValue;
	}
	
	public Integer getInt(String key,Integer defaultValue) {
		logger.debug(key);
		if(this.getProperty(key) != null) {
				return Integer.valueOf(this.getProperty(key));
		}
		return defaultValue;
	}
}
